package test_public;
import static org.junit.Assert.*;
import org.junit.Test;

import datamodel.rucksack.Rucksack;
import datamodel.tree.linked.LinkedTree;
import datamodel.tree.linked.LinkedTreeNode;

public class LinkedTreePublicTest {
	public LinkedTree lt = new LinkedTree();
	LinkedTreeNode currentNode = null;
	LinkedTreeNode root = new LinkedTreeNode(null);
	
	
	@Test
	public void moveToTest(){
		currentNode = root;
		Rucksack r = new Rucksack(10);
		LinkedTreeNode leftChild= new LinkedTreeNode(r);
		lt.setCurrentNode(currentNode);
		lt.setLeftNode(leftChild);
		
		assertEquals(true,lt.hasLeftNode());
		assertEquals(true,lt.moveToLeftNode());
		assertEquals(false,lt.hasRightNode());
		assertEquals(false,lt.moveToRightNode());
		assertEquals(lt.getCurrentNode(),root.getLeftChild());
		
	}
	
	@Test 
	public void setterTest(){
		currentNode = root;
		LinkedTreeNode leftChild= new LinkedTreeNode(null);
		LinkedTreeNode rightChild = new LinkedTreeNode(null);
		lt.setCurrentNode(currentNode);
	    lt.setLeftNode(leftChild);
	    lt.setRightNode(rightChild);
		
		assertTrue(lt.hasLeftNode());
		assertTrue(lt.hasRightNode());
		
	}
	@Test
	public void moveToRootTest(){
		currentNode = root;
		LinkedTreeNode leftChild= new LinkedTreeNode(null);
		LinkedTreeNode rightChild = new LinkedTreeNode(null);
		lt.setCurrentNode(currentNode);
	    lt.setLeftNode(leftChild);
	    lt.setRightNode(rightChild);
	    
	    lt.moveToLeftNode();
	    lt.moveToRoot();
	    assertEquals(root, lt.getCurrentNode());
	}
	@Test
	public void clear(){
		currentNode = root;
		LinkedTreeNode leftChild= new LinkedTreeNode(null);
		LinkedTreeNode rightChild = new LinkedTreeNode(null);
		lt.setCurrentNode(currentNode);
	    lt.setLeftNode(leftChild);
	    lt.setRightNode(rightChild);
	    
	    lt.clearTree();
	    assertEquals(null, lt.getCurrentNode());
	    assertEquals(false, lt.hasLeftNode());
	    assertEquals(false, lt.hasRightNode());
	    assertEquals(false, lt.hasParentNode());
	    
	}
	@Test
	public void EqualsTest(){
		// Tree 1
		lt.clearTree();
		currentNode = new LinkedTreeNode(new Rucksack(10));
		lt.setCurrentNode(currentNode);

		LinkedTreeNode leftChild= new LinkedTreeNode(new Rucksack(20));
		lt.setLeftNode(leftChild);
	    //lt.setRightNode(rightChild);
	    
		// Tree 2
	    LinkedTree lt2= new LinkedTree();
	    LinkedTreeNode currentNode2 = new LinkedTreeNode(new Rucksack(10));
	    lt2.setCurrentNode(currentNode2);
	    
	    LinkedTreeNode leftChild2= new LinkedTreeNode(new Rucksack(20));
	    lt2.setLeftNode(leftChild2);
	    
	    Rucksack r2= new Rucksack(30);
		LinkedTreeNode rightChild2 = new LinkedTreeNode(r2);
	    lt2.setRightNode(rightChild2);
	    
	    assertFalse(lt.equals(lt2));
	}
	@Test 
	public void EqualRucksackTest(){
		Rucksack r = new Rucksack(10);
		Rucksack r2= new Rucksack(10);
		
		assertTrue(r.equals(r2));
	}
	@Test
	public void LinkedTreeNodeEqualTest(){
		Rucksack r = new Rucksack(10);
		Rucksack r2= new Rucksack(10);
		LinkedTreeNode leftChild= new LinkedTreeNode(r);
		LinkedTreeNode rightChild = new LinkedTreeNode(r2);
		
		assertTrue(leftChild.equals(rightChild));
		
	}

}
